package com.gxa.saas.service.impl;

import com.gxa.saas.mapper.RouteDetailMapper;
import com.gxa.saas.mapper.RouteManagementMapper;
import com.gxa.saas.pojo.RouteManagement;
import com.gxa.saas.service.RouteDetailService;
import com.gxa.saas.service.RouteManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


@Service
@Transactional(rollbackFor = {Throwable.class})
public class RouteManagementServiceImpl implements RouteManagementService {

    @Autowired
    RouteManagementMapper routeManagementMapper;
    @Autowired
    RouteDetailMapper routeDetailMapper;

    @Override
    public List<RouteManagement> selectByPage(Integer page, Integer size) {
        return   routeManagementMapper.selectByPage(size*(page-1),size);
    }

    @Override
    public List<RouteManagement> selectByName(Map map) {
      return   routeManagementMapper.selectByName(map);
    }



    @Override

    public void update(RouteManagement routeManagement) {
        routeManagementMapper.update(routeManagement);
    }

    @Override
    public void delete(Integer id) {
        RouteManagement routeManagement = routeManagementMapper.selectById(id);
        String routeName = routeManagement.getRouteName();
        routeDetailMapper.deleteAll(routeName);
        routeManagementMapper.delete(id);
    }

    @Override
    public Integer add(RouteManagement routeManagement) {
     return routeManagementMapper.add(routeManagement);
    }

    @Override
    public RouteManagement selectByUp(Integer id) {
        return routeManagementMapper.selectByUp(id);
    }

    @Override
    public List<RouteManagement> selectAll() {
        List<RouteManagement> routeManagements = routeManagementMapper.selectAll();
        return  routeManagements;
    }

}
